package com.dl.Servlet;

import com.dl.Bean.Customer;
import com.dl.CustomerService.CustomerSerice;
import com.dl.CustomerServiceImpl.CustomerServiceImpl;
import com.dl.DaoImpl.CustomerYanzheng;
import com.dl.util.DBConnection;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/zhuce1")
public class zhuce1 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        Customer cs=new Customer();
        CustomerSerice css=new CustomerServiceImpl();
        cs.setName(request.getParameter("name"));//设置javaBean数据
        cs.setPassword(request.getParameter("password"));
        cs.setPhonenumber(request.getParameter("phonenumber"));
        cs.setIdcard(request.getParameter("idcard"));
        cs.setEmail(request.getParameter("email"));
        System.out.println(request.getParameter("name"));
        CustomerYanzheng yanzheng=new CustomerYanzheng();
        try {
            if(yanzheng.YanZheng(cs)==true){
                css.save(cs);
                System.out.println("cg");
                request.getRequestDispatcher("zhuceSuccess.jsp").forward(request, response) ;//跳转成功页面
            }else{
                System.out.println("sb");
               request.getRequestDispatcher("zhuceFalse.jsp").forward(request, response) ;//跳转错误页面
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }


    }
}
